﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jzy.Workflow.Task;

namespace Jzy.Web.WorkFlow.Fore.Controls
{
    public partial class Approves : System.Web.UI.UserControl
    {
        private string TaskID
        {
            get
            {
                return Request["TaskID"];
            }
        }

        protected string GetTaskState(object objState)
        {
            int state = (int)objState;
            if (state == (int)TaskState.待处理)
            {
                return "<span style='color:red;font-weight:bold;'>" + TaskState.待处理.ToString() + "</span>";
            }
            else
            {
                return ((TaskState)state).ToString();
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindView();
            }
        }

        private void BindView()
        {
            FlowTaskBO task = new FlowTaskBO();

            tr0.Visible = tr1.Visible = tr2.Visible = tr3.Visible = false;
            if (string.IsNullOrEmpty(TaskID))
            {
                tr0.Visible = true;
            }
            else
            {
                List<FlowTaskInfo> list = task.GetApprovedTask(TaskID);

                IEnumerable<FlowTaskInfo> lst1 = list.Where(Info => Info.FromType == (int)FromType.流转 || Info.FromType == (int)FromType.退回);
                lv1.DataSource = lst1.OrderByDescending(Info => Info.SendTime);
                lv1.DataBind();

                IEnumerable<FlowTaskInfo> lst2 = list.Where(Info => Info.FromType == (int)FromType.加签);
                lv2.DataSource = lst2.OrderByDescending(Info => Info.SendTime);
                lv2.DataBind();
                if (lst2.Count() > 0)
                {
                    tr2.Visible = true;
                }

                IEnumerable<FlowTaskInfo> lst3 = list.Where(Info => Info.FromType == (int)FromType.传阅);
                lv3.DataSource = lst3.OrderByDescending(Info => Info.SendTime);
                lv3.DataBind();
                if (lst3.Count() > 0)
                {
                    tr3.Visible = true;
                }

                if (lst2.Count() > 0 || lst3.Count() > 0)
                {
                    tr1.Visible = true;
                }
            }
        }
    }
}